<?php
namespace app\common\model;
class ChatMoney extends Base
{
    protected function initialize()
    {
        parent::initialize();
    }

    /* 红包类型 1平均 2随机 */
    public static function getRandArr($total, $num, $type=2){
        $min=0.01;
        $arr = array();
        if($type==1) {
          for($i=0;$i<$num;$i++) {
            $arr[] = round($total/$num,2);
          }
          return $arr;
        }
        $total = $total*100;
        $min = $min*100;
        for ($i=1;$i<$num;$i++)  {  
          $safe_total=($total-($num-$i)*$min)/($num-$i);//随机安全上限  
          $safe_total = max($safe_total,$min);
          $money=mt_rand($min,$safe_total);  
          $total=$total-$money;
          $arr[] = round($money/100,2);
        }
        $arr[] = round($total/100,2);
        return $arr;
      }
}